let EMAIL_REGEX = /^([a-zA-Z0-9]+[_|_|.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|_|.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/

/**
 * 必填验证规则
 */
function validateNecessary (tipInfo = '请输入', trigger = 'blur', isNeces = true) {
  return {
    required: isNeces,
    message: tipInfo,
    trigger
  }
}

/**
 * 长度验证规则
 */
function validateLength (min = 6, max = 32, name = null, trigger = 'blur') {
  return {
    min,
    max,
    message: (name === null ? '' : name) + '长度在' + min + '到' + max + '个字符',
    trigger
  }
}

/**
 * 邮箱正则验证
 */
function validateEmail (pattern = EMAIL_REGEX, message = '邮箱格式错误', trigger = 'blur') {
  return {
    pattern,
    message,
    trigger
  }
}

// TODO: 统一整合，使其调用形式为this.$*.*
// 统一整合
export default {
  necessary: function (tipInfo = '请输入', trigger = 'blur', isNeces = true) {
    return validateNecessary(tipInfo, trigger, isNeces)
  },
  length: function (min = 6, max = 32, name = null, trigger = 'blur') {
    return validateLength(min, max, name, trigger)
  },
  email: function (pattern = EMAIL_REGEX, message = '邮箱格式错误', trigger = 'blur') {
    return validateEmail(pattern, message, trigger)
  }
}
